﻿Imports MICROFORMA.BEL
Imports MICROFORMA.DIL
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.Common

Public Class DetalleLoteDA
    Implements DetalleLoteDI


    Public Function Add(ByVal _DetalleLote_BE As BEL.DetalleLoteBE) As String Implements DIL.DetalleLoteDI.Add
        Dim db As Database = DatabaseFactory.CreateDatabase()

        Try
            '_solicitud_BE.Fecha _
            Dim query As String = "insert into detallelote(IdLote, IdTipoDocumento, IdTipoContenedor, CantidadDocumentos, CantidadFolios,  EstadoDetalle, Estado, FechaCreacion, FechaModificacion) " _
                                    & "Values (" & _DetalleLote_BE.IdLote & "," & _DetalleLote_BE.IdTipoDocumento & "," & _DetalleLote_BE.IdTipoContenedor & "," _
                                    & _DetalleLote_BE.CantidadDocumentos & "," & _DetalleLote_BE.CantidadFolios & "," & IIf(_DetalleLote_BE.EstadoDetalle = True, 1, 0) & "" _
                                    & ",0,GETDATE(),GETDATE())"
            Dim o_dbCommand As DbCommand = db.GetSqlStringCommand(query)
            db.ExecuteNonQuery(o_dbCommand)
            Return "OK"

        Catch ex As Exception

            Return ex.Message.ToString

        End Try
    End Function

    Public Function Delete(ByVal Id As Integer) As String Implements DIL.DetalleLoteDI.Delete
        Dim db As Database = DatabaseFactory.CreateDatabase()

        Try
            Dim query As String = "Update DetalleLote Set estado=1" _
                                 & ", FechaModificacion=" & "getDate()" _
                                 & " where IdElemento=" & Id


            Dim o_dbCommand As DbCommand = db.GetSqlStringCommand(query)


            db.ExecuteNonQuery(o_dbCommand)


            Return "OK"

        Catch ex As Exception

            Return ex.Message.ToString

        End Try
    End Function

    Public Function Edit(ByVal _DetalleLote_BE As BEL.DetalleLoteBE) As String Implements DIL.DetalleLoteDI.Edit

    End Function

    Public Function getIdLastRecord() As Integer Implements DIL.DetalleLoteDI.getIdLastRecord

    End Function

    Public Function GetList() As System.Data.DataTable Implements DIL.DetalleLoteDI.GetList

    End Function

    Public Function List() As System.Data.DataTable Implements DIL.DetalleLoteDI.List

    End Function

    Public Function List_Id(ByVal Id As Integer) As System.Data.DataTable Implements DIL.DetalleLoteDI.List_Id

    End Function

    Public Function List_IdLote(ByVal Id As Integer) As System.Data.DataTable Implements DIL.DetalleLoteDI.List_IdLote
        Dim db As Database = DatabaseFactory.CreateDatabase()

        Dim query As String = "select *, (select nombre from tipocontenedor where idtipocontenedor = d.IdTipoContenedor)Contenedor, (select nombre from tipodocumental where IdPlantilla = d.IdTipoDocumento) Documento " & _
                                "from DetalleLote d  " & _
                                "where estado  = 0 and idlote = " & Id
        Dim dbCommand As DbCommand = db.GetSqlStringCommand(query)

        Dim productsDataSet As DataSet = Nothing

        productsDataSet = db.ExecuteDataSet(dbCommand)

        Return productsDataSet.Tables(0)

    End Function
End Class
